//
//  main.m
//  02-HomeWork
//
//  Created by dllo on 16/7/5.
//  Copyright © 2016年 daming. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
  
    //预习字符串创建及其方法, 找出对应以下内容的方法
    
    /** 初始化(init) */
    NSString *str = [[NSString alloc]init];
    
    /** 便利构造器(string) */
    NSString *str1 = [NSString string];
    
    /** 获取字符串长度(length) */
    NSString *str2 = @"Hello Word!";
    NSLog(@"%ld", [str2 length]);
    
    /** 获取字符串中字符(character) */
    unichar c = [str2 characterAtIndex:2];
    NSLog(@"%c", c);
    
    /** 字符串是否相等(equal) */
    NSString *str3 = @"hello word!";
    BOOL isEqual = [str2 isEqualToString:str3];
    if (isEqual) {
        NSLog(@"相等");
    } else {
        NSLog(@"不相等");
    }
    
    /** 获取子串(sub) */
    NSString *sub = [str2 substringFromIndex:5];
    NSLog(@"%@", sub);
    
    /** 拼接字符串(append) */
    NSString *str4 = @"lanou";
    NSString *append = [str2 stringByAppendingString:str4];
    NSLog(@"%@", append);
    /** 替换字符串(replace) */
    NSString *replace = [str2 stringByReplacingCharactersInRange:NSMakeRange(6, 4) withString:str4];
    NSLog(@"%@", replace);
    /** 字符串对象转化为int类型(int) */
    int a = 10;
    NSString *str5 = [NSString stringWithFormat:@"%d", a];
    int A = [str5 intValue];
    NSLog(@"%d", A);
    /** 字符串对象转化为其他数据类型, 例如double, float, BOOL等. */
    
    /** 字符串全部大写(uppercase) */
    NSString *upp = [str4 uppercaseString];
    NSLog(@"%@", upp);
    
    /** 字符串全部小写(lowercase) */
    NSString *low = [upp lowercaseString];
    NSLog(@"%@", low);
    /** 字符串首字母大写(capitalized) */
    NSString *cap = [str4 capitalizedString];
    NSLog(@"%@", cap);
    /** 是否以指定字符串为前缀(prefix) */
    NSString *str6 = @"www.baidu.com";
    if ([str6 hasPrefix:@"www"]) {
        NSLog(@"以www为前缀");
    } else {
        NSLog(@"不以www为前缀");
    }
    /** 是否以指定字符串为后缀(suffix) */
    if ([str6 hasSuffix:@"com"]){
        NSLog(@"以com为后缀");
    } else {
        NSLog(@"不以com为后缀");
    }
    
    
    
    
    
    return 0;
}
